package com.notifier;

import java.io.IOException;

public class ThreadRunner implements Runnable {
	
	AppContext ctx;
	HTTPGetUtility util;
	EmailUtility emailer;
	
	public ThreadRunner(AppContext ctx) throws IOException{
		this.ctx = ctx;
		util = new HTTPGetUtility();
		emailer = new EmailUtility(ctx);
	}

	@Override
	public void run() {
		
		try{
			String response = "";
			boolean found = false;
			
			while(!found){
				response = util.getHTTP();
				if(response.toLowerCase().contains("all tours are full")){
					System.out.println("All tours are full");
				}
				else{
					emailer.sendEmail();
					found = true;
				}
				Thread.sleep(30000);
			}
		}
		catch(InterruptedException e){
			System.out.println("Thread was interrupted");
		}
		
		
	}

}
